#!/bin/sh
#
# see: dh_installdeb(1)

set -e

package="doc-beaglebone-getting-started"

# summary of how this script can be called:
#        * <prerm> `remove'
#        * <old-prerm> `upgrade' <new-version>
#        * <new-prerm> `failed-upgrade' <old-version>
#        * <conflictor's-prerm> `remove' `in-favour' <package> <new-version>
#        * <deconfigured's-prerm> `deconfigure' `in-favour'
#          <package-being-installed> <version> `removing'
#          <conflicting-package> <version>
# for details, see http://www.debian.org/doc/debian-policy/ or
# the debian-policy package

remove_file () {
	if [ -f /var/cache/${package}/${wfile} ] ; then
		rm -f /var/cache/${package}/${wfile} || true
	fi
}

remove_dir () {
	if [ -d ${wdir} ] ; then
		rm -rf ${wdir} || true
	fi
}

remove_all() {
	wfile="beaglebone-getting-started-2015-12-04.img.xz" ; remove_file
	wfile="beaglebone-getting-started-2015-12-04.img" ; remove_file
	wfile="beaglebone-getting-started-2016-07-18.iso.xz" ; remove_file
	wfile="beaglebone-getting-started-2016-07-18.iso" ; remove_file
	wfile="beaglebone-getting-started-2016-11-07.img.xz" ; remove_file
	wfile="beaglebone-getting-started-2016-11-07.img" ; remove_file
	wfile="beaglebone-getting-started-2017-01-25.img.xz" ; remove_file
	wfile="beaglebone-getting-started-2017-01-25.img" ; remove_file
	wfile="beaglebone-getting-started-2017-05-25.img.xz" ; remove_file
	wfile="beaglebone-getting-started-2017-05-25.img" ; remove_file
	wfile="beaglebone-getting-started-2017-05-26.img.xz" ; remove_file
	wfile="beaglebone-getting-started-2017-05-26.img" ; remove_file
	wfile="beaglebone-getting-started-2018-09-13.img.xz" ; remove_file
	wfile="beaglebone-getting-started-2018-09-13.img" ; remove_file
	wfile="beaglebone-getting-started-2019-08-03.img.xz" ; remove_file
	wfile="beaglebone-getting-started-2019-08-03.img" ; remove_file
	wfile="beaglebone-getting-started-2019-10-31.img.xz" ; remove_file

	#Always keep the current one for quick reinstalls...
	#wfile="beaglebone-getting-started-2019-10-31.img" ; remove_file
}

case "$1" in
    remove|upgrade|deconfigure)
	remove_all
    ;;

    failed-upgrade)
    ;;

    *)
        echo "prerm called with unknown argument \`$1'" >&2
        exit 1
    ;;
esac

# dh_installdeb will replace this with shell code automatically
# generated by other debhelper scripts.

#DEBHELPER#

exit 0
